<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react@17.js"></script>
<script src="../react-dom@17.js"></script>
<script src="../babel.js"></script>
<script type="text/babel">
    let value;
    function myUseState(initState){
        console.log(initState)
        value = initState;
        let setValue = (newState)=>{
            value = newState;
            ReactDOM.render(<App/>,document.getElementById("root"))
        }
        return [value,setValue]
    }
    function App(){
        let num,setNum;
        if(value){
             [num,setNum] = myUseState(value)
        }else{
            
             [num,setNum] = myUseState(0)
        }
        console.log(num)
        return (
            <div>
                <h1>手写useState---{num}</h1>   
                <button onClick={()=>{
                    setNum(num+1)
                }}>++</button> 
            </div>
        )
    }
    ReactDOM.render(<App/>,document.getElementById("root"))
</script>
</html>